package com.atguigu.gmall.mq.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.mq.config.DelayedMqConfig;
import com.atguigu.gmall.mq.config.MQConfig;
import com.atguigu.gmall.rabbit.constants.MQConst;
import com.atguigu.gmall.rabbit.util.RabbitService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.ReactiveSubscription;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author: lx
 * @Time: 10:34
 * @Description:
 *
 * 生产者
 */
@RestController
@RequestMapping("/api/mq")
public class ProductMessageController {

/*    @Autowired
    private RabbitTemplate rabbitTemplate;//生产者
    //发消息
    @GetMapping("/sendMessage")
    public Result sendMessage(String message){
        rabbitTemplate.convertAndSend
                ("exchange11","routingkey11","111");
        return Result.ok();
    }*/
    ////////////////////下面正确的使用方式//////////////////////////////


    @Autowired
    private RabbitService rabbitService;
    //发消息
    @GetMapping("/sendMessage")
    public Result sendMessage(String message){
        rabbitService.sendMessage
                ("exchange11","routingkey11","111");
        return Result.ok();
    }

    //发死信交换机消息
    //发消息
    @GetMapping("/sendDeadMessage")
    public Result sendDeadMessage(String message){
        rabbitService.sendDeadMessage(MQConfig.exchange_dead,
                MQConfig.routing_dead_1,message,3);
        return Result.ok();
    }

    //发延迟 消息 基于 插件的
    @GetMapping("/sendDelayMessage")
    public Result sendDelayMessage(String message){
        rabbitService.sendDelayMessage(DelayedMqConfig.exchange_delay,
                DelayedMqConfig.routing_delay,message,6);
        return Result.ok();
    }


}
